import com.ycz.MyAutoWired;
import com.ycz.controller.UserController;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @Author:ycz
 * @date:2021/6/5
 */
public class Test2 {

    public static void main(String[] args) {
        UserController userController = new UserController();
        Class<? extends UserController> clazz = userController.getClass();
        // 获取所有属性的值
        Stream.of(clazz.getDeclaredFields()).forEach(field -> {
            MyAutoWired annotation = field.getAnnotation(MyAutoWired.class);
            if (Objects.nonNull(annotation)) {
                field.setAccessible(true);
                // 获取属性的类型
                Class<?> type = field.getType();
                try {
                    Object o = type.newInstance();
                    field.set(userController, o);
                } catch (Exception e) {
                }
            }
        });
        System.out.println(userController.getUserService());
    }

}
